#include "SimpleElementS.h"
#include "matrix.h"
#include "PubKeyEquationGroup.h"
#include "Initial.h"

#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <Integer.h>

int PublicKeyEquationTest()
{
	using namespace std;

	typedef SimpleElementS Element;
	InitialDimen(2, 3);
	size_t dimen = 3;
	Matrix<Element> plain(1,dimen),cipher(1,dimen),firstLinear(dimen,dimen),
		secondLinear(dimen,dimen),firstAffine(dimen,1),secondAffine(dimen,1);

	PubKeyEquationGroup equation;
	//	cout<<equation;

	string fileName;
	cout<<"Please input the file name:"<<endl;
	cin>>fileName;
	ifstream in(fileName.c_str());

	if(!in)
	{
		cout<<"The file can't open"<<endl;
		return 1;
	}

	in>>dimen;
	in>>plain;
	in>>firstLinear;
	in>>secondLinear;
	in>>firstAffine;
	in>>secondAffine;

	try{
		equation.applyLinear(firstLinear);
		equation.applyAdd(firstAffine);
		//		cout<<equation;
		equation.applyExp(17);
		//		cout<<equation;
		equation.applyLinear(secondLinear);
		equation.applyAdd(secondAffine);
	}catch(invalid_argument& e)
	{
		cout<<e.what();
	}

	cout<<equation;

	//	for(size_t i = 0; i < 1000000; i++)
	equation.encrypt(plain.getData()[0], cipher.getData()[0]);

	cout<<cipher;

	return 0;
}

// int main()
// {
// 	return PublicKeyEquationTest();
// }